TreeMenu: Don't manually reinvent g_list_index()
authorDaniel Boles <dboles.src@gmail.com>
Sat, 20 Oct 2018 14:19:11 +0000 (15:19 +0100)
committerDaniel Boles <dboles.src@gmail.com>
Wed, 7 Nov 2018 20:32:55 +0000 (20:32 +0000)
g_list_index() "Gets the position of the element containing the given
data (starting from 0)." That is exactly what we were manually doing.

gtk/gtktreemenu.c

index 6fb513d24f11ed62987622df1e0a01ced7aba78c..80db15419ff8b40ee6cd66804a426ff683b9effc 100644 (file)
@@ -876,18 +876,11 @@ static gint
 menu_item_position (GtkTreeMenu *menu,
                     GtkWidget   *item)
 {
-  GList *children, *l;
+  GList *children;
   gint   position;
 
   children = gtk_container_get_children (GTK_CONTAINER (menu));
-  for (position = 0, l = children; l; position++, l = l->next)
-    {
-      GtkWidget *iitem = l->data;
-
-      if (item == iitem)
-        break;
-    }
-
+  position = g_list_index (children, item);
   g_list_free (children);
 
   return position;